package app.beit.finportal.service.convert;

import java.util.ArrayList;
import java.util.List;

import app.beit.finportal.bean.WebboardBean;
import app.beit.finportal.entity.Webboard;

public class WebboardConvert {

	/**
	 * Convert Entity To Bean
	 * @param entity
	 * @return NewsBean
	 */
	public static WebboardBean entityToBean(final Webboard entity) throws Exception {
		final WebboardBean bean = new WebboardBean();
		
		bean.setId(entity.getId());
		bean.setName(entity.getName());
		bean.setContent(entity.getContent());
		bean.setViewed(entity.getViewed());
		bean.setReplied(entity.getReplied());
		bean.setListWebboardReply(entity.getListWebboardReply());
		bean.setCreatedBy(entity.getCreatedBy());
		bean.setCreatedDate(entity.getCreatedDate());
		
		return bean;
	}
	
	/**
	 * Convert Bean to Entity
	 * @param bean
	 * @return Webboard
	 */
	public static Webboard beanToEntity(final WebboardBean bean){
		final Webboard entity = new Webboard();

		entity.setId(bean.getId());
		entity.setName(bean.getName());
		entity.setContent(bean.getContent());
		entity.setViewed(bean.getViewed());
		entity.setReplied(bean.getReplied());
		entity.setListWebboardReply(bean.getListWebboardReply());
		entity.setCreatedBy(bean.getCreatedBy());
		entity.setCreatedDate(bean.getCreatedDate());
		
		return entity;
	}

	/**
	 * Convert List Entity to List Bean
	 * @param entities
	 * @return List NewsBean
	 */
	public static List<WebboardBean> entityToBean(final List<Webboard> entities) throws Exception{
		final List<WebboardBean> beans = new ArrayList<WebboardBean>();
		
		for(final Webboard entity : entities){
			beans.add(WebboardConvert.entityToBean(entity));
		}
		
		return beans;
	}
	
	/**
	 * Convert List Bean to List Entity
	 * @param beans
	 * @return List News
	 */
	public static List<Webboard> beanToEntity(final List<WebboardBean> beans){
		final List<Webboard> entities = new ArrayList<Webboard>();
		
		for(final WebboardBean bean : beans){
			entities.add(WebboardConvert.beanToEntity(bean));
		}
		
		return entities;
	}
	
}
